package com.copm.ifm.servers.sys.controller;

import com.copm.ifm.base.api.pojo.PageDTO;
import com.copm.ifm.base.api.pojo.PageVO;
import com.copm.ifm.base.basic.ServiceResponse;
import com.copm.ifm.base.basic.util.AuthUtil;
import com.copm.ifm.base.service.base.BaseController;
import com.copm.ifm.servers.sys.client.SysProjectDetailClient;
import com.copm.ifm.servers.sys.dto.SysProjectDetailPageDTO;
import com.copm.ifm.servers.sys.entity.SysProjectDetail;
import com.copm.ifm.servers.sys.service.SysProjectDetailService;
import com.copm.ifm.servers.sys.vo.SysProjectDetailPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 项目明细
 * </p>
 *
 * @author tp
 * @since 2020-12-16
 */
@Api(tags = "项目明细/sys-project-detail")
@RestController
@RequestMapping("/sys-project-detail")
public class SysProjectDetailController extends BaseController implements SysProjectDetailClient {

    @Resource
    SysProjectDetailService sysProjectDetailService;

    @Override
    @ApiOperation("分页")
    @PostMapping("/page")
    public ServiceResponse<PageVO<SysProjectDetailPageVO>> page(@RequestBody PageDTO<SysProjectDetailPageDTO> param) {
        PageVO<SysProjectDetailPageVO> result = sysProjectDetailService.selectForPage(param);
        return success(result);
    }

    @Override
    @ApiOperation("查询-根据id")
    @GetMapping("/by/id")
    public ServiceResponse<SysProjectDetail> getById(@ApiParam(value = "主键id", required = true)
                                                     @RequestParam int id) {
        SysProjectDetail sysProjectDetail = sysProjectDetailService.selectById(id);
        if (StringUtils.isEmpty(sysProjectDetail)) {
            return fail("查询失败，无效数据");
        }
        return success(sysProjectDetail);
    }

    @Override
    @ApiOperation("保存-项目save明细表")
    @PostMapping
    public ServiceResponse<SysProjectDetail> save(SysProjectDetail entity) {
        AuthUtil.getCurrentUserId();
        sysProjectDetailService.save(entity);
        return success(entity);
    }
}
